{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from torch.autograd import Variable\n",
    "import torch.nn.functional as F\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = torch.unsqueeze(torch.linspace(-1 , 1, 100), dim=1)\n",
    "y = x.pow(2)+0.2*torch.rand(x.size())\n",
    "x, y = Variable(x), Variable(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAdS0lEQVR4nO3df4wcZ33H8fc3x6VcCs0FckB8jokrpQ5FgRiugWJa4tA0ThDYhFYJIH41yHJLKhKpFkaVKBVCORq1BEQgMm4UaBFxVVzjQqihdWikBFNfiPM7Ds7vO1NyJHEocCK28+0fu+uM92Zmn9mdmd2Z/bwky96d2d3HszvfffY73+d5zN0REZHqO67fDRARkXwooIuI1IQCuohITSigi4jUhAK6iEhNKKCLiNREx4BuZteZ2RNmdnfC9vea2Z3NP7ea2Wvzb6aIiHQS0kO/HliTsv1h4C3u/hrgU8DmHNolIiIZvaDTDu5+s5mdlrL91sjN3cDS3pslIiJZdQzoGV0KfCdkx5NPPtlPO+20nF9eRKTebrvttp+5+0TcttwCupmtphHQ35yyz3pgPcCyZcuYmZnJ6+VFRIaCmT2atC2XKhczew2wBVjr7k8m7efum919yt2nJiZiv2BERKRLPQd0M1sGbAPe5+4P9N4kERHpRseUi5l9HTgHONnMZoG/AUYB3P1a4BPAS4EvmhnAYXefKqrBIi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I3d/CfgUjXZ+Cvh74M9KbNcqdz9gZi8Dvmdm9zd7FV3L8Xi9iMaJd7m7/7x5d9fHK+4lYu4LnQq6kM9ah9dcvKPZahoB/c2Ru3N/TzO060c00om/aF7f2E5j5bKBOF400i23uHu011zU8QpR6OerrwHd3f+ox6dIm7b3p9ZcNan5k+aJPNplZlme9wLgR+7+08hzH/23mX0Z+FaZ7XL3A82/nzCzf6PxU+9m+ny8zGyURjD/mrtvizx318crRi9TQR8f8Ngi24WZvQbYAlzg7k+27k95TwtvV+SLF3e/0cy+aGYnhzy2yHZFLPqFXODxClHo56vqKZe0qX13AB9o/vsDQEiPP0SW512Uu2sGtZZ3ArFXw4tol5n9ppm9uPVv4I8jr9+342VmBvwjcJ+7/0PbtjyPVy9TQYc8trB2mdkyYBvwPnd/IHJ/2ntaRrte0Xz/MLOzacSUJ0MeW2S7mu05EXgLkc9cwccrRLGfryKu9Obxh8bJOwv8GvgpsLN5/xLgxsh+F9KoiniQRqqmdf9Lgf8Cftz8+yU5tSv2eWPadQKND/aJbY//J+Au4M7mG3ZKWe2icQX9juafewbleNFIH3jzmOxt/rmwiOMV93kBNgAbmv82GouiP9h83am0x+b4ee/Uri3A05HjM9PpPS2pXZc1X/cOGhdr3zQIx6t5+4PADW2PK/p4fR34CXCIRvy6tMzPl0aKiojURNVTLiIi0qSALiJSEwroIiI1oYAuIlITCugiIjWhgC4iUhMK6CIiNaGALiJSE/8P/EPeoD1eskgAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(x.data.numpy(), y.data.numpy())\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Net(torch.nn.Module):\n",
    "    def __init__(self, n_feature, n_hidden, n_output):\n",
    "        super().__init__()\n",
    "        self.hidden = torch.nn.Linear(n_feature, n_hidden)\n",
    "        self.predict = torch.nn.Linear(n_hidden, n_output)\n",
    "    \n",
    "    def forward(self, x):\n",
    "        x = F.relu(self.hidden(x))\n",
    "        x = self.predict(x)\n",
    "        return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Net(\n",
      "  (hidden): Linear(in_features=1, out_features=10, bias=True)\n",
      "  (predict): Linear(in_features=10, out_features=1, bias=True)\n",
      ")\n"
     ]
    }
   ],
   "source": [
    "net = Net(1, 10, 1)\n",
    "print(net)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "optimizer = torch.optim.SGD(net.parameters(), lr=0.1)\n",
    "loss_func = torch.nn.MSELoss()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor(0.1137, grad_fn=<MseLossBackward>)\n",
      "tensor(0.1328, grad_fn=<MseLossBackward>)\n",
      "tensor(0.1041, grad_fn=<MseLossBackward>)\n",
      "tensor(0.0965, grad_fn=<MseLossBackward>)\n",
      "tensor(0.1283, grad_fn=<MseLossBackward>)\n",
      "tensor(0.1231, grad_fn=<MseLossBackward>)\n",
      "tensor(0.0934, grad_fn=<MseLossBackward>)\n",
      "tensor(0.1105, grad_fn=<MseLossBackward>)\n",
      "tensor(0.1333, grad_fn=<MseLossBackward>)\n",
      "tensor(0.1071, grad_fn=<MseLossBackward>)\n",
      "tensor(0.0948, grad_fn=<MseLossBackward>)\n",
      "tensor(0.1260, grad_fn=<MseLossBackward>)\n",
      "tensor(0.1257, grad_fn=<MseLossBackward>)\n",
      "tensor(0.0946, grad_fn=<MseLossBackward>)\n",
      "tensor(0.1074, grad_fn=<MseLossBackward>)\n",
      "tensor(0.1334, grad_fn=<MseLossBackward>)\n",
      "tensor(0.1102, grad_fn=<MseLossBackward>)\n",
      "tensor(0.0935, grad_fn=<MseLossBackward>)\n",
      "tensor(0.1234, grad_fn=<MseLossBackward>)\n",
      "tensor(0.1281, grad_fn=<MseLossBackward>)\n"
     ]
    }
   ],
   "source": [
    "for t in range(100):\n",
    "    prediction = net(x)\n",
    "    \n",
    "    loss = loss_func(prediction, y)\n",
    "    loss.backward()\n",
    "    optimizer.step()\n",
    "    \n",
    "    if t%5 == 0:\n",
    "        print(loss)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.7 64-bit",
   "language": "python",
   "name": "python37764bita7c2719225b84763be647c75e40e67b2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
